package view;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseListener;
import javax.swing.JPanel;

import model.Image;

@SuppressWarnings("serial")
public class Thumbnail extends JPanel implements IImagePanel, IView {
	
	private Image image;
	
	public Thumbnail(Image image) {
		this.image = image;
		image.disable();
		
		image.registerObserver(this);
	}
	
	@Override
	public void update() {
		repaint();
	}
	
	@Override
	public void paintComponent(Graphics graphics) {
		super.paintComponent(graphics);
		Graphics2D graphics2D = (Graphics2D)graphics;
		if(image.isEnable()) {
		graphics2D.drawImage(
					image.getImage().getScaledInstance(this.getHeight(),
													   this.getWidth(), 0),
													   0, 0, this);
		}
	}
	
	public void addChangeImageListener(MouseListener listener) {
		this.addMouseListener(listener);
	}

}